package wxk.interview.nio.service.impl;

import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import wxk.interview.nio.service.DownloadService;

import java.io.*;
import java.nio.CharBuffer;
import java.nio.channels.FileChannel;

/**
 * @author wangxuekai
 * @version 2.2
 * @Date 2017/3/17.
 * @since 2.2
 */
public class DownloadServiceImpl implements DownloadService{


    public void download(String url, String fName) throws IOException {
        CloseableHttpClient client = HttpClients.createDefault();
        HttpGet request = new HttpGet(url);

        HttpResponse response = client.execute(request);
        InputStream inputStream = null;

        if (response.getStatusLine().getStatusCode() == 200){
            inputStream = response.getEntity().getContent();
        }
        if (inputStream == null){
            throw new RuntimeException("failed download");
        }


        //todo

    }


}
